<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Page;
use App\Models\Category;
use App\Models\Post;

class PageController extends Controller
{

    public function index($slug)
    {
        $pages = Page::where('slug', $slug)->get();
        if ($slug == 'editorial-policies') {
            $cate = Category::where('slug', '=', $slug)->first();
            $editorials = Post::where('cate_id', '=', $cate->id)->get();
            return view('page.index', ['editorials' => $editorials]);
        }
    	return view('page.index', ['pages' => $pages]);
    }

    public function editorial($id)
    {
        $editorial = Post::find($id);
        return view('page.editorial', ['editorial' => $editorial]);
    }
}
